﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RED_NET_Core.BLL;
using RED_NET_Core.Entity;
namespace RED_NET.ContentPage.User
{
    public partial class MyAttentionList : System.Web.UI.Page
    {
        public static int uid;
        public static int visitId;
        protected void Init()
        {
            Session["PageName"] = "MyAttentionList";
            uid = (int)Session["USER_ID"];
            if (Request.QueryString["VISIT_ID"] != null)
                visitId = Int32.Parse(Request.QueryString["VISIT_ID"]);
            else
                Response.Redirect("~/ContentPage/Error/PageError.aspx");
            if (visitId != uid)
                Response.Redirect("~/ContentPage/Error/PageError.aspx");
            LoginBLL _login=new LoginBLL();
            DataTable _dt = _login.GetMyAttentionInfo(uid);
            GridView_MyAttention.DataSource = _dt;

            GridView_MyAttention.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //检测用户是否登录
                if (Session["USER_ID"] == null)
                {
                    Response.Write("<script>('请先登录！');location.href='Index.aspx';</script>");
                }
                Init();
            }
        }
        protected void GridView_MyAttention_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView_MyAttention.PageIndex = e.NewPageIndex;
            Init(); //重新绑定GridView数据的函数
            GridView_MyAttention.PageIndex = e.NewPageIndex;

        }
        protected void GridView_MyAttention_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow )
            {
                e.Row.Cells[1].Visible = false; //如果想使第1列不可见,则将它的可见性设为false
                e.Row.Cells[2].Visible = false;
                LinkButton LinkButton_Delete = (LinkButton)e.Row.FindControl("LinkButton_Delete");
                LinkButton_Delete.CommandArgument = e.Row.RowIndex.ToString();

            }
        }
        protected void GridView_MyAttention_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                int _index = Convert.ToInt32(e.CommandArgument);
                int _Id = Int32.Parse(GridView_MyAttention.Rows[_index].Cells[2].Text);
                LoginBLL _login = new LoginBLL();
                //  GridView_MyAttention.DataKeys[e.RowIndex].Value.ToString();
                try
                {
                    _login.DeleteUserRel(_Id);
                }
            catch (Exception ex)
            {
                Response.Redirect("~/ContentPage/Error/PageError.aspx");
            }
                Response.Redirect(Request.Url.ToString());
            }

        }
    }
}
